<?php require_once('../conn/DBconnect.php'); ?>
<?php
	
	$emailErr = "Invalid email";
	
	$checkEmail = false;
	if(isset($_POST["v_check_email"]) && $_POST["v_check_email"] == true)
		$checkEmail = true;
		
 	$params[0] = $_POST["v_table"];
 	$params[1] = $_POST["v_column"];
 	$params[2] = $_POST["v_value"];
 	$params[3] = $_POST["v_method"];
 	
 	if($checkEmail)
 	{
 		if (filter_var($_POST["v_value"], FILTER_VALIDATE_EMAIL)) {
 			//executeValidation($params);
 			$validatePROC = "CALL SP_VALIDATOR('" . implode("', '", $params) . "');";
			$result = mysqli_query($mysqlLink, $validatePROC);
			 	
			$info_result = mysqli_fetch_array($result, MYSQLI_ASSOC);
			echo $info_result["err_code"];
 		}
 		else
 			echo $emailErr;
 	}
 	else
 	{
 		//executeValidation(params);
	    $validatePROC = "CALL SP_VALIDATOR('" . implode("', '", $params) . "');";
		$result = mysqli_query($mysqlLink, $validatePROC);
		 	
		$info_result = mysqli_fetch_array($result, MYSQLI_ASSOC);
		echo $info_result["err_code"];
 	}
 	
 	function executeValidation($params)
 	{
 		$validatePROC = "CALL SP_VALIDATOR('" . implode("', '", $params) . "');";
		$result = mysqli_query($mysqlLink, $validatePROC);
		 	
		$info_result = mysqli_fetch_array($result, MYSQLI_ASSOC);
		echo $info_result["err_code"];
 	}
?>